package com.faithbj.device.web.controller;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.faithbj.device.model.configuration.Pager;
import com.faithbj.device.model.entity.Article;
import com.faithbj.device.service.ArticleService;



@Controller
@RequestMapping("/article")
public class ArticleController implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3191027650216346092L;
	
	@Resource
	private ArticleService articleService;
	
	@RequestMapping("/list")
	public String article(Pager pager,ModelMap map) {
		List<Article> newest=articleService.getArticleList("4028824038224e29013822522c380000", 0, 10);
		List<Article> announce=articleService.getArticleList("402881e4382b3d6a01382b6028740004", 0, 10);
		
		map.put("newest", newest);
		map.put("announce", announce);
		
		
		pager=articleService.findByPager(pager);
		map.put("pager", pager);	
		
		return "web/article";
	}

	// 文章搜索
	@RequestMapping("/search")
	public String search(Pager pager,ModelMap map) throws Exception {
		if (pager == null) {
			pager = new Pager();
			pager.setPageSize(Article.DEFAULT_ARTICLE_LIST_PAGE_SIZE);
		}
		pager = articleService.findByPager(pager);
		map.put("pager",pager);
		
		List<Article> newest=articleService.getArticleList("4028824038224e29013822522c380000", 0, 10);
		List<Article> announce=articleService.getArticleList("402881e4382b3d6a01382b6028740004", 0, 10);
		
		map.put("newest", newest);
		map.put("announce", announce);
		
		return "web/article_search";
	}
	
	@RequestMapping("/{id}")
	public String content(ModelMap map,@PathVariable("id") String id){
		List<Article> newest=articleService.getArticleList("4028824038224e29013822522c380000", 0, 10);
		List<Article> announce=articleService.getArticleList("402881e4382b3d6a01382b6028740004", 0, 10);
		
		map.put("newest", newest);
		map.put("announce", announce);
		
		
		Article article = articleService.get(id);
		map.put("article", article);
		return "web/article_content";
	}
}
